package com.sfac.java_spring_boot_02.modules.test.dao;

import com.sfac.java_spring_boot_02.modules.test.entity.Country;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description CountryDao
 * @Author wang
 * @Date 2021/9/14 9:04
 */
@Repository
@Mapper
public interface CountryDao {
    @Select("select * from test_country where country_id=#{countryId}")
    @Results(id="countryResults", value = {
            @Result(column = "country_id", property = "countryId"),
            @Result(column = "country_id",
                    property = "cities", javaType= List.class,
                    many=@Many(select = "com.sfac.javaSpringBoot.modules.test." +
                            "dao.CityDao.getCitiesByCountryId"))
    })
    Country getCountryByCountryId(int countryId);

    @Select("select * from test_country where country_name=#{countryName}")
    @ResultMap(value = {"countryResults"})
    Country getCountryByCountryName(String countryName);
}
